package leetcode;

import java.util.Arrays;

/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q2482.java
 * @Author : WangRuoyu
 * @Date 2023/2/24 10:34
 */
public class Q2482 {
    public int[][] onesMinusZeros(int[][] grid) {
        int[][] res = new int[grid.length][grid[0].length];

        int[] m = new int[grid.length];
        int[] n = new int[grid[0].length];

        for (int i = 0; i < m.length; ++i) {
            for (int j = 0; j < n.length; ++j) {
                m[i] += grid[i][j];
                n[j] += grid[i][j];
            }
        }

        for (int i = 0; i < m.length; ++i) {
            for (int j = 0; j < n.length; ++j) {
                res[i][j] = 2 * (m[i] + n[j]) - m.length - n.length;
            }
        }

        return res;
    }

    public static void main(String[] args) {
        Q2482 sl = new Q2482();
        int[][] grid = {{0, 1, 1}, {1, 0, 1}, {0, 0, 1}};
        for (int[] a : sl.onesMinusZeros(grid)) {
            System.out.println(Arrays.toString(a));
        }
    }
}
